import Vue from 'vue'
import App from './App'

import store from './store'
import loading from "@/pages/selectUser/components/Loading.vue"
// 导入API模块
import api from './api/index.js';

Vue.config.productionTip = false

Vue.prototype.$store = store
// 挂载API到Vue原型
Vue.prototype.$api = api

App.mpType = 'app'

const app = new Vue({
	store,
	...App
})
app.$mount()
//统一提示
global.show_nativeUI_toast = function(msg, icontype = 'success'){
	const iconTypeUrl = {
	    error: '/static/toast-image/warn.png',
	    success: '/static/toast-image/success.png',
	    warn: '/static/toast-image/warn.png'
	}
	uni.showToast({
	    title: msg,
		image: iconTypeUrl[icontype]
	})
}


// 判断token 是否有效
Vue.prototype.checkToken = function(callback) {

	let uniIdToken = uni.getStorageSync('uni_id_token')

    console.log("12312312",uniIdToken)
	if (uniIdToken) {
		// 使用新的API模块替代uniCloud.callFunction
		this.$api.user.checkToken().then(res => {
			if (res.code == 200) {
				//callback(true)
			} else {
				//callback(false)
				uni.showToast({
					title:"登录信息过期，请重新登录！",
					icon:'none'
				})
				const value = uni.getStorageSync('launchFlag');
				// #ifdef APP-PLUS
				if (value) {
					// launchFlag=true直接跳转到首页
					uni.reLaunch({
						url: '/pages/login/login'
					});
				} else
                {
					uni.reLaunch({
						url: '/pages/index/loading'
					});
				}

				// #endif
				// #ifdef  MP||H5
				uni.reLaunch({
					url: '/pages/login/login'
				});
				// #endif
			}
		}).catch(err => {
			console.error('Token验证失败666:', err)
			//callback(false)
			// 网络错误时也跳转到登录页
			const value = uni.getStorageSync('launchFlag');
			// #ifdef APP-PLUS
			if (value) {
				uni.reLaunch({
					url: '/pages/login/login'
				});
			} else {
				uni.reLaunch({
					url: '/pages/index/loading'
				});
			}
			// #endif
			// #ifdef  MP||H5
			uni.reLaunch({
				url: '/pages/login/login'
			});
			// #endif
		})
	} else {
		//callback(false)
		const value = uni.getStorageSync('launchFlag');
		// #ifdef APP-PLUS
		if (value) {
			// launchFlag=true直接跳转到首页
			uni.reLaunch({
				url: '/pages/login/login'
			});
		} else {
			uni.reLaunch({
				url: '/pages/index/loading'
			});
		}
		// #endif
		// #ifdef  MP||H5
		uni.reLaunch({
			url: '/pages/login/login'
		});
		// #endif
	}
}



// uni.reLaunch({
// 			url: '/pages/login/login'
//  		});

Vue.prototype.carColor = function(e){
	let color =  [{
        "text": "黑色",
        "value": 0
      }, {
        "text": "银色",
        "value": 1
      }, {
        "text": "白色",
        "value": 2
      }, {
        "text": "红色",
        "value": 3
      }, {
        "text": "黄色",
        "value": 4
      }, {
        "text": "橙色",
        "value": 5
      }, {
        "text": "蓝色",
        "value": 6
      }]
	  let colorValue = color[e]?color[e].text:''
	  	return colorValue
}

global.emotionMap = function() {
	let emotionMapData = [
		[{
				"url": "emoji_0@2x.png",
				"alt": "[NO]"
			},
			{
				"url": "emoji_1@2x.png",
				"alt": "[OK]"
			},
			{
				"url": "emoji_2@2x.png",
				"alt": "[下雨]"
			},
			{
				"url": "emoji_3@2x.png",
				"alt": "[么么哒]"
			},
			{
				"url": "emoji_4@2x.png",
				"alt": "[乒乓]"
			},
			{
				"url": "emoji_5@2x.png",
				"alt": "[便便]"
			},
			{
				"url": "emoji_6@2x.png",
				"alt": "[信封]"
			},
			{
				"url": "emoji_7@2x.png",
				"alt": "[偷笑]"
			},
			{
				"url": "emoji_8@2x.png",
				"alt": "[傲慢]"
			},
			{
				"url": "emoji_9@2x.png",
				"alt": "[再见]"
			},
			{
				"url": "emoji_10@2x.png",
				"alt": "[冷汗]"
			},
			{
				"url": "emoji_11@2x.png",
				"alt": "[凋谢]"
			},
			{
				"url": "emoji_140@2x.png",
				"alt": "[鼓掌]"
			},
			{
				"url": "emoji_13@2x.png",
				"alt": "[删除]"
			},
			{
				"url": "emoji_14@2x.png",
				"alt": "[勾引]"
			},
			{
				"url": "emoji_15@2x.png",
				"alt": "[发呆]"
			},
			{
				"url": "emoji_16@2x.png",
				"alt": "[发抖]"
			},
			{
				"url": "emoji_17@2x.png",
				"alt": "[可怜]"
			},
			{
				"url": "emoji_18@2x.png",
				"alt": "[可爱]"
			},
			{
				"url": "emoji_19@2x.png",
				"alt": "[右哼哼]"
			},
			{
				"url": "emoji_20@2x.png",
				"alt": "[右太极]"
			},
			{
				"url": "emoji_21@2x.png",
				"alt": "[右车头]"
			},
			{
				"url": "emoji_22@2x.png",
				"alt": "[吐]"
			},
			{
				"url": "emoji_23@2x.png",
				"alt": "[吓]"
			}
		],
		[{
				"url": "emoji_24@2x.png",
				"alt": "[咒骂]"
			},
			{
				"url": "emoji_25@2x.png",
				"alt": "[咖啡]"
			},
			{
				"url": "emoji_26@2x.png",
				"alt": "[啤酒]"
			},
			{
				"url": "emoji_27@2x.png",
				"alt": "[嘘]"
			},
			{
				"url": "emoji_28@2x.png",
				"alt": "[回头]"
			},
			{
				"url": "emoji_29@2x.png",
				"alt": "[困]"
			},
			{
				"url": "emoji_30@2x.png",
				"alt": "[坏笑]"
			},
			{
				"url": "emoji_31@2x.png",
				"alt": "[多云]"
			},
			{
				"url": "emoji_32@2x.png",
				"alt": "[大兵]"
			},
			{
				"url": "emoji_33@2x.png",
				"alt": "[大哭]"
			},
			{
				"url": "emoji_34@2x.png",
				"alt": "[太阳]"
			},
			{
				"url": "emoji_35@2x.png",
				"alt": "[奋斗]"
			},
			{
				"url": "emoji_36@2x.png",
				"alt": "[奶瓶]"
			},
			{
				"url": "emoji_37@2x.png",
				"alt": "[委屈]"
			},
			{
				"url": "emoji_38@2x.png",
				"alt": "[害羞]"
			},
			{
				"url": "emoji_39@2x.png",
				"alt": "[尴尬]"
			},
			{
				"url": "emoji_40@2x.png",
				"alt": "[左哼哼]"
			},
			{
				"url": "emoji_41@2x.png",
				"alt": "[左太极]"
			},
			{
				"url": "emoji_42@2x.png",
				"alt": "[左车头]"
			},
			{
				"url": "emoji_43@2x.png",
				"alt": "[差劲]"
			},
			{
				"url": "emoji_44@2x.png",
				"alt": "[弱]"
			},
			{
				"url": "emoji_45@2x.png",
				"alt": "[强]"
			},
			{
				"url": "emoji_46@2x.png",
				"alt": "[彩带]"
			},
			{
				"url": "emoji_47@2x.png",
				"alt": "[彩球]"
			}
		],
		[{
				"url": "emoji_48@2x.png",
				"alt": "[得意]"
			},
			{
				"url": "emoji_49@2x.png",
				"alt": "[微笑]"
			},
			{
				"url": "emoji_50@2x.png",
				"alt": "[心碎了]"
			},
			{
				"url": "emoji_51@2x.png",
				"alt": "[快哭了]"
			},
			{
				"url": "emoji_52@2x.png",
				"alt": "[怄火]"
			},
			{
				"url": "emoji_53@2x.png",
				"alt": "[怒]"
			},
			{
				"url": "emoji_54@2x.png",
				"alt": "[惊恐]"
			},
			{
				"url": "emoji_55@2x.png",
				"alt": "[惊讶]"
			},
			{
				"url": "emoji_56@2x.png",
				"alt": "[憨笑]"
			},
			{
				"url": "emoji_141@2x.png",
				"alt": "[龇牙]"
			},
			{
				"url": "emoji_58@2x.png",
				"alt": "[打哈欠]"
			},
			{
				"url": "emoji_59@2x.png",
				"alt": "[抓狂]"
			},
			{
				"url": "emoji_60@2x.png",
				"alt": "[折磨]"
			},
			{
				"url": "emoji_61@2x.png",
				"alt": "[抠鼻]"
			},
			{
				"url": "emoji_62@2x.png",
				"alt": "[抱抱]"
			},
			{
				"url": "emoji_63@2x.png",
				"alt": "[抱拳]"
			},
			{
				"url": "emoji_64@2x.png",
				"alt": "[拳头]"
			},
			{
				"url": "emoji_65@2x.png",
				"alt": "[挥手]"
			},
			{
				"url": "emoji_66@2x.png",
				"alt": "[握手]"
			},
			{
				"url": "emoji_67@2x.png",
				"alt": "[撇嘴]"
			},
			{
				"url": "emoji_68@2x.png",
				"alt": "[擦汗]"
			},
			{
				"url": "emoji_69@2x.png",
				"alt": "[敲打]"
			},
			{
				"url": "emoji_70@2x.png",
				"alt": "[晕]"
			},
			{
				"url": "emoji_71@2x.png",
				"alt": "[月亮]"
			}
		],
		[{
				"url": "emoji_72@2x.png",
				"alt": "[棒棒糖]"
			},
			{
				"url": "emoji_73@2x.png",
				"alt": "[汽车]"
			},
			{
				"url": "emoji_74@2x.png",
				"alt": "[沙发]"
			},
			{
				"url": "emoji_75@2x.png",
				"alt": "[流汗]"
			},
			{
				"url": "emoji_76@2x.png",
				"alt": "[流泪]"
			},
			{
				"url": "emoji_77@2x.png",
				"alt": "[激动]"
			},
			{
				"url": "emoji_78@2x.png",
				"alt": "[灯泡]"
			},
			{
				"url": "emoji_79@2x.png",
				"alt": "[炸弹]"
			},
			{
				"url": "emoji_80@2x.png",
				"alt": "[熊猫]"
			},
			{
				"url": "emoji_81@2x.png",
				"alt": "[爆筋]"
			},
			{
				"url": "emoji_82@2x.png",
				"alt": "[爱你]"
			},
			{
				"url": "emoji_83@2x.png",
				"alt": "[爱心]"
			},
			{
				"url": "emoji_84@2x.png",
				"alt": "[爱情]"
			},
			{
				"url": "emoji_85@2x.png",
				"alt": "[猪头]"
			},
			{
				"url": "emoji_86@2x.png",
				"alt": "[猫咪]"
			},
			{
				"url": "emoji_87@2x.png",
				"alt": "[献吻]"
			},
			{
				"url": "emoji_88@2x.png",
				"alt": "[玫瑰]"
			},
			{
				"url": "emoji_89@2x.png",
				"alt": "[瓢虫]"
			},
			{
				"url": "emoji_90@2x.png",
				"alt": "[疑问]"
			},
			{
				"url": "emoji_91@2x.png",
				"alt": "[白眼]"
			},
			{
				"url": "emoji_92@2x.png",
				"alt": "[皮球]"
			},
			{
				"url": "emoji_93@2x.png",
				"alt": "[睡觉]"
			},
			{
				"url": "emoji_94@2x.png",
				"alt": "[磕头]"
			},
			{
				"url": "emoji_95@2x.png",
				"alt": "[示爱]"
			}
		],
		[{
				"url": "emoji_96@2x.png",
				"alt": "[礼品袋]"
			},
			{
				"url": "emoji_97@2x.png",
				"alt": "[礼物]"
			},
			{
				"url": "emoji_98@2x.png",
				"alt": "[篮球]"
			},
			{
				"url": "emoji_99@2x.png",
				"alt": "[米饭]"
			},
			{
				"url": "emoji_100@2x.png",
				"alt": "[糗大了]"
			},
			{
				"url": "emoji_101@2x.png",
				"alt": "[红双喜]"
			},
			{
				"url": "emoji_102@2x.png",
				"alt": "[红灯笼]"
			},
			{
				"url": "emoji_103@2x.png",
				"alt": "[纸巾]"
			},
			{
				"url": "emoji_104@2x.png",
				"alt": "[胜利]"
			},
			{
				"url": "emoji_105@2x.png",
				"alt": "[色]"
			},
			{
				"url": "emoji_106@2x.png",
				"alt": "[药]"
			},
			{
				"url": "emoji_138@2x.png",
				"alt": "[麦克风]"
			},
			{
				"url": "emoji_108@2x.png",
				"alt": "[蛋糕]"
			},
			{
				"url": "emoji_109@2x.png",
				"alt": "[蜡烛]"
			},
			{
				"url": "emoji_110@2x.png",
				"alt": "[街舞]"
			},
			{
				"url": "emoji_111@2x.png",
				"alt": "[衰]"
			},
			{
				"url": "emoji_112@2x.png",
				"alt": "[西瓜]"
			},
			{
				"url": "emoji_113@2x.png",
				"alt": "[调皮]"
			},
			{
				"url": "emoji_114@2x.png",
				"alt": "[象棋]"
			},
			{
				"url": "emoji_115@2x.png",
				"alt": "[跳绳]"
			},
			{
				"url": "emoji_116@2x.png",
				"alt": "[跳跳]"
			},
			{
				"url": "emoji_117@2x.png",
				"alt": "[车厢]"
			},
			{
				"url": "emoji_118@2x.png",
				"alt": "[转圈]"
			},
			{
				"url": "emoji_119@2x.png",
				"alt": "[鄙视]"
			}
		],
		[
			{
				"url": "emoji_120@2x.png",
				"alt": "[酷]"
			},
			{
				"url": "emoji_121@2x.png",
				"alt": "[钞票]"
			},
			{
				"url": "emoji_122@2x.png",
				"alt": "[钻戒]"
			},
			{
				"url": "emoji_123@2x.png",
				"alt": "[闪电]"
			},
			{
				"url": "emoji_124@2x.png",
				"alt": "[闭嘴]"
			},
			{
				"url": "emoji_125@2x.png",
				"alt": "[闹钟]"
			},
			{
				"url": "emoji_126@2x.png",
				"alt": "[阴险]"
			},
			{
				"url": "emoji_127@2x.png",
				"alt": "[难过]"
			},
			{
				"url": "emoji_128@2x.png",
				"alt": "[雨伞]"
			},
			{
				"url": "emoji_129@2x.png",
				"alt": "[青蛙]"
			},
			{
				"url": "emoji_130@2x.png",
				"alt": "[面条]"
			},
			{
				"url": "emoji_131@2x.png",
				"alt": "[鞭炮]"
			},
			{
				"url": "emoji_132@2x.png",
				"alt": "[风车]"
			},
			{
				"url": "emoji_133@2x.png",
				"alt": "[飞吻]"
			},
			{
				"url": "emoji_134@2x.png",
				"alt": "[飞机]"
			},
			{
				"url": "emoji_135@2x.png",
				"alt": "[饥饿]"
			},
			{
				"url": "emoji_136@2x.png",
				"alt": "[香蕉]"
			},
			{
				"url": "emoji_137@2x.png",
				"alt": "[骷髅]"
			}
		]
	]
	return emotionMapData
}
Vue.component('loading',loading)

//判断昵称是否存在
// Vue.prototype.checkNickname = function(callback) {
// 	let nickname = uni.getStorageSync('userInfo').nickname?uni.getStorageSync('userInfo').nickname:uni.getStorageSync('userInfo').username?uni.getStorageSync('userInfo').username:uni.getStorageSync('userInfo').mobile?uni.getStorageSync('userInfo').mobile:''
// 	let uid = uni.getStorageSync('userInfo')._id
// 	if (nickname) {
// 		//callback(true)
// 	}else{
// 		//callback(false)
// 		uni.showToast({
// 			title:"请维护个人信息！",
// 			icon:'none'
// 		})
//
// 		setTimeout(function() {
// 		    uni.redirectTo({
// 		    	url: '/pages/contacts/edit?id=' + uid
// 		    });
// 		}, 1000);
// 	}
//
// };